package com.demo2.servlet;

import com.lagou.Request;
import com.lagou.Response;
import com.lagou.servlet.HttpServlet;

import java.io.IOException;

/**
 * @description
 * @date 2021-08-17 22:47
 * @author xiaol
 */
public class LagouServlet implements HttpServlet {

	@Override
	public void doGet(Request request, Response response) throws IOException {
		String str = "demo2 doGet";
		String resp = "HTTP/1.1 200 OK \n" +
				"Content-Type: text/html \n" +
				"Content-Length: " + str.getBytes().length + "\n" +
				"\r\n" + str;
		response.getOutputStream().write(resp.getBytes());
	}

	@Override
	public void doPost(Request request, Response response) throws IOException {
		String str = "demo2 doPost";
		String resp = "HTTP/1.1 200 OK \n" +
				"Content-Type: text/html \n" +
				"Content-Length: " + str.getBytes().length + "\n" +
				"\r\n" + str;
		response.getOutputStream().write(resp.getBytes());
	}

	@Override
	public void service(Request req, Response resp) throws IOException {
		if("GET".equals(req.getMethod())){
			doGet(req,resp);
		}else{
			doPost(req,resp);
		}
	}

}
